package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowSorter;
import javax.swing.SpringLayout;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import CommonGui.NotEdditibleTable;
import DataObjects.BusinessMenuLeftList;
import DataObjects.BusinessMenuRightList;
import DataObjects.ConstantObjects;
import DataObjects.StandardMenuLeftList;
import DataObjects.StandardMenuRightList;
import Messages.MessageAddNewBusinessMenu;


import Messages.MessageGetAllSupplierItems;
import Messages.MessageGetCostRecipeByName;
import Messages.MessageGetCostRecipeByNameReply;
import Messages.MessageGetRecipesToLeftListForAddBussMenu;
import Messages.MessageGetRecipesToLeftListForAddBussMenuReply;
import Messages.MessageGetRecipesToLeftListForUpdBussMenu;
import Messages.MessageGetRecipesToLeftListForUpdBussMenuReply;
import Messages.MessageGetRecipesToRightListForUpdBussMenu;
import Messages.MessageGetRecipesToRightListForUpdBussMenuReply;
import Messages.MessageUpdateBusinessMenu;

import Messages.MessageGetSupplierItemsReply;
import Messages.MessageSavingReply;
import Messages.MessageShowBusinessMenusReply;

import Messages.MessageShowBusinessMenus;
import Messages.MessageShowIDMenu;
import Messages.MessageShowIdMenuReply;


/**
 * 
 * @author Andrey,Igor
 * Class for updating existing  business menu in DB 
 *
 */
public class PfUpdateBusinessMenu extends JPanel{
	
	
	private JPanel totalPanel;
	private JPanel bulkiPanel;
	private int count_res_menuRecipes=0;
	private int mId;
	private String flagStatusOfMenu="פעיל";
	private String menu_flag="business";
	private JComboBox statusMenu;
	private JComboBox typeChooseCB;
	private float cost;
	private float totalCost=0;
	private String flagTypeChooseOfRecipe="בחר סוג";
	
	private JTextField recipeTxt;
	private JTextField roleTxt;
	private JTextField weightTxt;
	private JTextField	costTxt;
	private JTextField textField_MenuId;
	private JTextField	textField_nameMenu;
	private JTextField textField_price;
	private JTextField costItemTxt;
	private JTextField reallyCostItemTxt;
	private JTextField nameTF1;
	private JTextField nameTF2;
	
	private RowSorter<DefaultTableModel> sorterName;
	
	private String business_menu="business";     //Flag that information to server about which the menu this(standard or business)
	
	private String menuId;
	private MainMenu mainMenu;
	
	private JPanel leftPanel;
	private JPanel rightPanel;
	private JPanel detailsPanel;
	private JPanel tablePanel;
	private JPanel allItemsPanel;
	private JPanel middlePanel;
	private JPanel suppItemsPanel;
	private JPanel  allRecipesListPanel;
	private JPanel allRecipesPanelSearch;
	private JPanel menuRecipesPanelSearch;
	private JPanel menuRecipeListPanel;
	private JPanel buttonsPanel;
	private JPanel costMenuPanel;
	
	private JList allRecipesList;
	private JList menuRecipesList;
	private DefaultListModel allRecipeModel;
	private DefaultListModel menuRecipesModel;
	
	private Vector<BusinessMenuLeftList> res_allRecipesTemp;
	private Vector<BusinessMenuLeftList> res_allRecipes;                 
	private Vector<BusinessMenuRightList> res_menuRecipes; 
	private Vector <String> tblheader;
	private Vector<String> menuDetails; 
	
	private JButton leftButton;
	private JButton rightButton;
	
	private JTable tbl;
	private DefaultTableModel dtm;
	private Component horizontalGlue;
	
	DefaultTableCellRenderer centerRenderer;
	
	public PfUpdateBusinessMenu (MainMenu mm,Vector<String> menu)
	{
		super();
		this.mainMenu=mm;
		this.menuDetails=menu;
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		initialize();
	
		
		
	}
	
	
	private void initialize()
	{
		add(getLeftPanel());
		add(getRightPanel());
		
	}
	
	
	//====================== panels for leftPanel	========================================
	/**
	 * Method for creation Panel(LeftPanel) that includes two panel(BulkiPanel - for two Jlists and buttons
	 *  and CostMenuPanel - to show total cost of recipes that selected) 
	 * @return JPanel
	 */
	
		private JPanel getLeftPanel()             
		{
			
			leftPanel=new JPanel();
			leftPanel.setBorder(new TitledBorder(null, "בניית תפריט חדש", TitledBorder.CENTER, TitledBorder.TOP, null, null));
			leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
			leftPanel.add(getBulkiPanel());
			leftPanel.add(getCostMenuPanel());
			return leftPanel;
		}
	
		/**
		 * Method getCostMenuPanel need to creating panel with  TextField that show total cost of selected recipes
		 * @return JPanel costMenuPanel
		 */
		private JPanel	getCostMenuPanel()
		{
			
			costMenuPanel=new JPanel();
			GridBagLayout gbll = new GridBagLayout();    
			costMenuPanel.setLayout(gbll);
			GridBagConstraints gbc1 = new GridBagConstraints();
			GridBagConstraints gbc2 = new GridBagConstraints();
			
			gbc1.ipadx = 5;
			gbc1.ipady =15;
			
			
			
			gbc1.gridheight=1;
			gbc1.gridwidth=0;
			gbc1.insets = new Insets(0,400,0,0);
			
			gbc2.gridheight=1;
			gbc2.gridwidth=0;
			gbc2.insets = new Insets(0,400,0,0);
			
			JLabel tWeightLbl=new JLabel("סהכ:");
			costMenuPanel.add(tWeightLbl,gbc1);
			
			costMenuPanel.add(getCostTxt(),gbc1);
			
		return costMenuPanel;
			
		}
		
		/**
		 * Method getCostTxt for creation of  TextField that show total cost of selected recipes.Used by method getCostMenuPanel
		 * @return
		 */
		
		private JTextField getCostTxt()
		{
			
			costTxt=new JTextField();
			costTxt.setHorizontalAlignment(JTextField.RIGHT);
			costTxt.setColumns(10);
			int size_vector=res_menuRecipes.size();	
			for(int i=0;i<size_vector;i++) 
			{
				
				totalCost=(res_menuRecipes.get(i).getReallyCost()+totalCost);
			
			}
			costTxt.setText(Float.toString(totalCost));
			
		return costTxt;
		}
		
		/**
		 * Method  for creation  of panel that includes three panels(AllRecipesPanel,MiddlePanel,MenuRecipesPanel)
		 * @return JPanel bulkiPanel
		 */
		
		private JPanel getBulkiPanel()
		{
			
			bulkiPanel=new JPanel();
			
			bulkiPanel.setLayout(new BoxLayout(bulkiPanel, BoxLayout.X_AXIS));
			bulkiPanel.add(getAllRecipesPanel());        //panel with searchPanel(searchTxt+searchLbl) + listPanel(list with all recipes) 
			bulkiPanel.add(getMiddlePanel());;         // panel with right and left buttons + textfield for recipe + textfield for role + textfield for Weight
			bulkiPanel.add(getMenuRecipesPanel());
		return bulkiPanel;
		}
		
		/**
		 * Method for creation of panel with AllRecipesPanelSearch(searchTxt+searchLbl) + allRecipesListPanel(list with all recipes) 
		 * @return JPanel allItemsPanel
		 */
			
		private JPanel getAllRecipesPanel()
		{
			
			allItemsPanel=new JPanel();
			allItemsPanel.setLayout(new BoxLayout(allItemsPanel, BoxLayout.Y_AXIS));
			allItemsPanel.add(getAllRecipesPanelSearch());
			allItemsPanel.add(getListAllRecipesPanel());		
		return allItemsPanel;

		}
		
		/**
		 * Method for creation of panel that includes JList and inserts all recipes into it.
		 * @return JPanel allRecipesListPanel
		 */
		
		private JPanel getListAllRecipesPanel ()
		{
			
			allRecipesListPanel=new JPanel();
			allRecipesListPanel.setLayout(new BoxLayout(allRecipesListPanel, BoxLayout.X_AXIS));	
			allRecipeModel=new DefaultListModel();
			res_allRecipesTemp=new Vector<BusinessMenuLeftList>();
			MessageGetRecipesToLeftListForUpdBussMenu allRecipes=new MessageGetRecipesToLeftListForUpdBussMenu(menuDetails.get(0));
			MessageGetRecipesToLeftListForAddBussMenu allRecipesForRes_allRecipesTemp=new MessageGetRecipesToLeftListForAddBussMenu();
			try {
				mainMenu.ms.client.sendToServer(allRecipes);
				MessageGetRecipesToLeftListForUpdBussMenuReply result = (MessageGetRecipesToLeftListForUpdBussMenuReply)mainMenu.ms.client.GetMessage();
				mainMenu.ms.client.sendToServer(allRecipesForRes_allRecipesTemp);
				MessageGetRecipesToLeftListForAddBussMenuReply resultForRes_allRecipesTemp = (MessageGetRecipesToLeftListForAddBussMenuReply)mainMenu.ms.client.GetMessage();
				this.res_allRecipes=result.getRecipes();
				this.res_allRecipesTemp=resultForRes_allRecipesTemp.getRecipes();
				
			} catch (IOException e) {
				e.printStackTrace();
			}		
			
			int size_vector=res_allRecipes.size();		
			for(int i=0;i<size_vector;i++) 
			{
				allRecipeModel.addElement((String) res_allRecipes.get(i).getName());  
				
			}
			
			allRecipesList = new JList(allRecipeModel);	
			allRecipesList.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
			allRecipesList.setFont(new Font("Tahoma", Font.PLAIN, 14));
			allRecipesList.setBackground(new Color(230, 230, 250));
			JScrollPane listScroller1 = new JScrollPane(allRecipesList);
			listScroller1.setPreferredSize(new Dimension(200, 600));
			allRecipesListPanel.add(listScroller1);
			String selectedItem=(String)allRecipesList.getSelectedValue();
			
			allRecipesList.addListSelectionListener(new ListSelectionListener() 
		 	{
		 	      public void valueChanged(ListSelectionEvent evt) {
		 	        if (evt.getValueIsAdjusting())
		 	        return;
		 	      	     
		 	      JList itemList=(JList) evt.getSource();
		          String value=(String) itemList.getSelectedValue();
		          int index=allRecipesList.getSelectedIndex();
		          menuRecipesList.clearSelection();
		          allRecipesList.setSelectedIndex(index);
		          recipeTxt.setText(value);
		          roleTxt.setEditable(true);
				  costItemTxt.setEditable(true);
		         
		       
		          for(int i=0;i<res_allRecipes.size();i++) 
			  		{
			        	  
			        	  if(value==(null))
			        		  break;
			  			if(value.equals(res_allRecipes.get(i).getName()))
			  			{
			  				costItemTxt.setText("");
			  				costItemTxt.setText(Float.toString( res_allRecipes.get(i).getCost()+res_allRecipes.get(i).getConstCost()));
			  			    roleTxt.setText("");
			  		        reallyCostItemTxt.setText("");
			  		        weightTxt.setText("");
		 	       
			  			}
			  		}	
		 	   
		 	      }
		 	    });
		
			return allRecipesListPanel;
		}
		
		/**
		 * Method for creation JText filters to quick searching of recipes by name
		 * @return  JPanel allRecipesPanelSearch
		 * 
		 */
		private JPanel getAllRecipesPanelSearch()           
		{
					
			allRecipesPanelSearch=new JPanel();
			allRecipesPanelSearch.setLayout(new BoxLayout(allRecipesPanelSearch, BoxLayout.X_AXIS));
			JLabel searchLbl=new JLabel(":חיפוש לפי שם המתכון");
			allRecipesPanelSearch.add(getNameTF1());
			allRecipesPanelSearch.add(searchLbl);
			return allRecipesPanelSearch;
		}
		
		
		private JTextField getNameTF1()
		{
			nameTF1=new JTextField(20);
			nameTF1.setHorizontalAlignment(JTextField.RIGHT);
		
			KeyListener keyListener = new KeyListener() 
			{		      
				public void keyPressed(KeyEvent arg0) {}

				public void keyReleased(KeyEvent arg0) 
				{
					JTextField nameField = (JTextField)arg0.getSource();
					String selectedName = (String)nameField.getText();
					filterByName1(selectedName);				
				}

				public void keyTyped(KeyEvent arg0) {}		
			};
			
			nameTF1.addKeyListener(keyListener);		
			return nameTF1;
		}
		
		//filter for all items list
		private void filterByName1(String str)
		{
			allRecipeModel.clear();
			for(int i=0;i<res_allRecipes.size();i++)
			{
				if(((String)res_allRecipes.get(i).getName()).startsWith(str))
					allRecipeModel.addElement((String) res_allRecipes.get(i).getName());  
			}
		}
		/**
		 * Method for creation panel that uncludes two panels(MenuRecipesPanelSearch,ListMenuRecipePanel)
		 * @return JPanel suppItemsPanel
		 */		
		private JPanel getMenuRecipesPanel()               
		{
			
			suppItemsPanel=new JPanel();
			suppItemsPanel.setLayout(new BoxLayout(suppItemsPanel, BoxLayout.Y_AXIS));
			suppItemsPanel.add(getMenuRecipesPanelSearch());
			suppItemsPanel.add(getListMenuRecipePanel());
			return suppItemsPanel;

		}
		
		/**
		 * Method for creation of panel that includes JList and inserts all recipes that selected into it.
		 * @return JPanel menuRecipeListPanel
		 */				
		
		private JPanel getListMenuRecipePanel ()          
		{
			
			menuRecipeListPanel=new JPanel();
			
			menuRecipeListPanel.setLayout(new BoxLayout(menuRecipeListPanel, BoxLayout.X_AXIS));	
			menuRecipesModel=new DefaultListModel();
			MessageGetRecipesToRightListForUpdBussMenu menuRecipes=new MessageGetRecipesToRightListForUpdBussMenu(menuDetails.get(0),menu_flag);
			try {
				mainMenu.ms.client.sendToServer(menuRecipes);
				MessageGetRecipesToRightListForUpdBussMenuReply result = (MessageGetRecipesToRightListForUpdBussMenuReply)mainMenu.ms.client.GetMessage();
				this.res_menuRecipes=result.getResultRecipes();
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			int size_vector=res_menuRecipes.size();		
			for(int i=0;i<size_vector;i++)
			{
				menuRecipesModel.addElement((String) res_menuRecipes.get(i).getName());  
			}
			
			menuRecipesList = new JList(menuRecipesModel);	
			menuRecipesList.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
			menuRecipesList.setFont(new Font("Tahoma", Font.PLAIN, 14));
			menuRecipesList.setBackground(new Color(230, 230, 250));
			JScrollPane listScroller2 = new JScrollPane(menuRecipesList);
			listScroller2.setPreferredSize(new Dimension(200, 600));
			menuRecipeListPanel.add(listScroller2);
			menuRecipesList.addListSelectionListener(new ListSelectionListener() 
			{
		 	      public void valueChanged(ListSelectionEvent evt) {
		 	        if (evt.getValueIsAdjusting())
		 	        return;
		 	      	     
		 	      JList itemList=(JList) evt.getSource();
		          String value=(String) itemList.getSelectedValue();
		          int index=menuRecipesList.getSelectedIndex();
	              allRecipesList.clearSelection();
		          menuRecipesList.setSelectedIndex(index);
		          recipeTxt.setText(value);
		          while(count_res_menuRecipes<res_menuRecipes.size()){
		        	  
	           	   if(value==(res_menuRecipes.get(count_res_menuRecipes).getName())){
	           		
	           	//	reallyCostItemTxt.setText((String) res_menuRecipes.get(count_res_menuRecipes).get(2));
	           		reallyCostItemTxt.setText(Float.toString( res_menuRecipes.get(count_res_menuRecipes).getReallyCost()));
	           		weightTxt.setText(Integer.toString( res_menuRecipes.get(count_res_menuRecipes).getQuantity()));  
	           		roleTxt.setText( res_menuRecipes.get(count_res_menuRecipes).getRole()); 
	           		costItemTxt.setText(Float.toString( res_menuRecipes.get(count_res_menuRecipes).getCost()));
	           		typeChooseCB.setSelectedItem(res_menuRecipes.get(count_res_menuRecipes).getIsSelectable());
	           		   
	           		roleTxt.setEditable(false);
					recipeTxt.setEditable(false);
					//weightTxt.setEditable(false);
					reallyCostItemTxt.setEditable(false);
	           	   }
		          count_res_menuRecipes++;
		          }
		          count_res_menuRecipes=0;
		 	      mainMenu.validate();
		 	      }
		 	    });
				
		return menuRecipeListPanel;
		}
		     
		/**
		 * Method for creation JTextFields filters to quick searching of recipes by name
		 * @return  JPanel menuRecipesPanelSearch
		 * 
		 */
		private JPanel getMenuRecipesPanelSearch()                    
		{
			
			menuRecipesPanelSearch=new JPanel();
			menuRecipesPanelSearch.setLayout(new BoxLayout(menuRecipesPanelSearch, BoxLayout.X_AXIS));
			JLabel searchLbl=new JLabel("חיפוש לפי שם המוצר :");
			menuRecipesPanelSearch.add(getNameTF2());
			menuRecipesPanelSearch.add(searchLbl);
			
		return menuRecipesPanelSearch;
		}
		
		
		private JTextField getNameTF2()
		{
			nameTF2=new JTextField(20);
			nameTF2.setHorizontalAlignment(JTextField.RIGHT);
		
			KeyListener keyListener = new KeyListener() 
			{		      
				public void keyPressed(KeyEvent arg0) {}

				public void keyReleased(KeyEvent arg0) 
				{
					JTextField nameField = (JTextField)arg0.getSource();
					String selectedName = (String)nameField.getText();
					filterByName2(selectedName);				
				}

				public void keyTyped(KeyEvent arg0) {}		
			};
			
			nameTF2.addKeyListener(keyListener);		
			return nameTF2;
		}
		
		//filter for all items list
		private void filterByName2(String str)
		{
			menuRecipesModel.clear();
			for(int i=0;i<res_menuRecipes.size();i++)
			{
				if(((String)res_menuRecipes.get(i).getName()).startsWith(str))
					menuRecipesModel.addElement((String) res_menuRecipes.get(i).getName());  
			}
		}
		/**
		 * Method for creation panel that includes buttons "right" and "left" and JTextFields for any details of selected recipe
		 * (name of recipe,role,quantity of recipe,cost of recipe,really cost of recipe) and comboBox for choose kind of recipe
		 * @return middlePanel
		 */		
		private JPanel getMiddlePanel()                                 
		{
			   
				middlePanel=new JPanel();
				GridBagLayout gbl = new GridBagLayout();    
				middlePanel.setLayout(gbl);
				GridBagConstraints gbc1 = new GridBagConstraints();
				GridBagConstraints gbc2 = new GridBagConstraints();
				GridBagConstraints gbc3 = new GridBagConstraints();
				GridBagConstraints gbc4 = new GridBagConstraints();
				GridBagConstraints gbc5 = new GridBagConstraints();
				GridBagConstraints gbc6 = new GridBagConstraints();
				GridBagConstraints gbc7 = new GridBagConstraints();
				GridBagConstraints gbc8 = new GridBagConstraints();
				GridBagConstraints gbc9 = new GridBagConstraints();
				GridBagConstraints gbc10 = new GridBagConstraints();
				GridBagConstraints gbc11 = new GridBagConstraints();
				GridBagConstraints gbc12 = new GridBagConstraints();
				GridBagConstraints gbc13 = new GridBagConstraints();
				GridBagConstraints gbc14 = new GridBagConstraints();
				
				gbc1.fill=GridBagConstraints.HORIZONTAL;
				gbc1.gridheight=1;
				gbc1.gridwidth=0;
				gbc1.insets = new Insets(0,0,50,0);
				
				gbc4.fill=GridBagConstraints.HORIZONTAL;
				gbc4.gridheight=1;
				gbc4.gridwidth=0;
				gbc4.insets = new Insets(0,0,50,0);
			
				
				gbc2.gridheight=1;
				gbc2.gridwidth=0;
				gbc2.insets = new Insets(0,0,0,0);
				
				gbc6.gridheight=1;
				gbc6.gridwidth=0;
				gbc6.insets = new Insets(0,0,0,0);
						
				gbc5.gridheight=1;
				gbc5.gridwidth=0;
				gbc5.insets = new Insets(0,0,20,0);
						
				gbc3.gridheight=1;
				gbc3.gridwidth=0;
				gbc3.insets = new Insets(0,0,20,0);
						
				gbc7.gridheight=1;
				gbc7.gridwidth=0;
				gbc7.insets = new Insets(0,0,0,0);
				
				gbc8.gridheight=1;
				gbc8.gridwidth=0;
				gbc8.insets = new Insets(0,0,20,0);
				
				gbc9.gridheight=1;
				gbc9.gridwidth=0;
				gbc9.insets = new Insets(0,0,0,0);
				
				gbc10.gridheight=1;
				gbc10.gridwidth=0;
				gbc10.insets = new Insets(0,0,20,0);
						
				gbc11.gridheight=1;
				gbc11.gridwidth=0;
				gbc11.insets = new Insets(0,0,0,0);
				
				gbc12.gridheight=1;
				gbc12.gridwidth=0;
				gbc12.insets = new Insets(0,0,20,0);
				
				gbc13.gridheight=1;
				gbc13.gridwidth=0;
				gbc13.insets = new Insets(0,0,0,0);
				
				gbc14.gridheight=1;
				gbc14.gridwidth=0;
				gbc14.insets = new Insets(0,0,20,0);
						
				middlePanel.add(getRightButton(),gbc1);

				middlePanel.add(getLeftButton(),gbc4);
				
				JLabel nameItemLbl=new JLabel("מתכון :");
				middlePanel.add(nameItemLbl,gbc2);
				middlePanel.add(getRecipeTxt(),gbc5);	

				JLabel measureItemLbl=new JLabel("מקום בתפריט :");
				middlePanel.add(measureItemLbl,gbc6);		
				middlePanel.add(getRoleTxt(),gbc3);
				
				JLabel costLbl=new JLabel("עלות כללית למתכון :");
				middlePanel.add(costLbl,gbc9);
				middlePanel.add(getCostItemTxt(),gbc10);
										
				JLabel tWeightLbl=new JLabel("כמות :");
				middlePanel.add(tWeightLbl,gbc7);
				middlePanel.add(getWeightTxt(),gbc8);
				
				
				
				JLabel reallyCostLbl=new JLabel("עלות לפי חישוב המערכת :");
				middlePanel.add(reallyCostLbl,gbc11);
				middlePanel.add(getReallyCostItemTxt(),gbc12);
				
				JLabel typeChooseLbl=new JLabel("סוג מתכון :");
				middlePanel.add(typeChooseLbl,gbc13);
				middlePanel.add(getTypeChooseRecipe(),gbc14);
				
			return middlePanel;
			}
		
		/**
		 * Method to creation comboBox for choosing kind of recipe(fixed in this menu or not)
		 * @return typeChooseCB
		 */
		private JComboBox getTypeChooseRecipe()
		{
			Vector<String> typeChoose=new Vector<String>();
			typeChoose.add("בחר סוג");
			typeChoose.add("לבחירה");
			typeChoose.add("קבוע");
		    typeChooseCB=new JComboBox(typeChoose);
			typeChooseCB.addActionListener(new java.awt.event.ActionListener() 
		  	{
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JComboBox typeChooseCBox = (JComboBox)e.getSource();
				    String selectedType = (String)typeChooseCBox.getSelectedItem(); 
				    if(selectedType.equals("לבחירה") || selectedType.equals("קבוע"))
				    {
				    	if(selectedType.equals("לבחירה"))
				    		flagTypeChooseOfRecipe=("לבחירה");
				    	else
				    		flagTypeChooseOfRecipe="קבוע";
				    		typeChooseCB.setBackground(Color.pink);
				  	}
				    else
				    {
				    	 	typeChooseCB.setBackground(Color.RED);
				    }
				
					} 
			});	
			return typeChooseCB;
		}
		
		/**
		 * Methods for creation JTextFields for any details of selected recipe
		 * (name of recipe,role,quantity of recipe,cost of recipe,really cost of recipe)
		 * @return JTextFields ...
		 */
		private JTextField getRoleTxt()
		{
			roleTxt=new JTextField();
			roleTxt.setHorizontalAlignment(JTextField.RIGHT);
			roleTxt.setColumns(10);
			roleTxt.setEditable(false);
		return roleTxt;
		}
		
		
		private JTextField getRecipeTxt()
		{
			recipeTxt=new JTextField();
			recipeTxt.setHorizontalAlignment(JTextField.RIGHT);
			recipeTxt.setColumns(10);
			recipeTxt.setEditable(false);

		return recipeTxt;
		}
		
		
		
		
		private JTextField getCostItemTxt()
		{
			costItemTxt=new JTextField();
			costItemTxt.setHorizontalAlignment(JTextField.RIGHT);
			costItemTxt.setColumns(10);
			costItemTxt.setEditable(false);

		return costItemTxt;
		}
		
		private JTextField getReallyCostItemTxt()
		{
			reallyCostItemTxt=new JTextField();
			reallyCostItemTxt.setHorizontalAlignment(JTextField.RIGHT);
			reallyCostItemTxt.setColumns(10);
			reallyCostItemTxt.setEditable(false);
		return reallyCostItemTxt;
		}
		
		
		private JTextField getWeightTxt()
		{
			weightTxt=new JTextField();
			weightTxt.setHorizontalAlignment(JTextField.RIGHT);
			weightTxt.setColumns(10);
			//weightTxt.setEditable(false);
			weightTxt.addKeyListener(keyListener1);
			
		return weightTxt;
		}
		
		/**
		 * KeyListener for the JTextField weightTxt (quantity of anything item) for calculate cost of selected recipe by quantity
		 */
		//=========================================================	KeyListener for the JTextField weightTxt (quantity of anything item)========================================
		KeyListener keyListener1 = new KeyListener() 
		{		      
			public void keyPressed(KeyEvent arg0) {}

			public void keyReleased(KeyEvent arg0) 
			{
			/*	MessageGetCostRecipeByName msgShowPrice=new MessageGetCostRecipeByName(recipeTxt.getText() );   //esle ne nujno to mojno steret etot message
				
				try {
					mainMenu.ms.client.sendToServer(msgShowPrice);
					MessageGetCostRecipeByNameReply resultID=(MessageGetCostRecipeByNameReply)mainMenu.ms.client.GetMessage();
					price=Float.parseFloat(resultID.getRecipeCost());	
				    price=price*(Float.parseFloat(weightTxt.getText()));
				    costItemTxt.setText(Float.toString(price));
				    reallyCostItemTxt.setText(Float.toString(price));
				} catch (IOException e) {
					
					e.printStackTrace();
				}*/
				if(weightTxt.getText().isEmpty())
					reallyCostItemTxt.setText("");
				else{
				cost=Float.parseFloat(costItemTxt.getText());
				cost=cost*(Float.parseFloat(weightTxt.getText()));
				reallyCostItemTxt.setText(Float.toString(cost));
				}
			}
			
			public void keyTyped(KeyEvent arg0) {}		
		};
		//====================================================================================================================================================================	
			
	    	/**
			 * Method for creation JButton 	rightButton that transfer selected recipe from JList with all recipes to JList with 
			 * selected recipes  of new menu
			 * @return rightButton
			 */		
		private JButton getRightButton()
		{
			
			rightButton=new JButton("--->");
			res_menuRecipes = new Vector<BusinessMenuRightList>();
			rightButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
				String selectedItem=(String)allRecipesList.getSelectedValue();
				
				 flagTypeChooseOfRecipe=(String) typeChooseCB.getSelectedItem();
					if (selectedItem!=null)
					{
						if(roleTxt.getText().isEmpty()){
				    		 JOptionPane.showMessageDialog(null,"יש לתת למנה מקום בתפריט");
				    		 return;
				    				 }
						else{
							if(weightTxt.getText().isEmpty()){
					    		 JOptionPane.showMessageDialog(null,"יש לקבוע כמות המנות");
					    		 return;	
							}
							try{
								
								Integer f=Integer.parseInt(roleTxt.getText());
								
							}catch(NumberFormatException e1)
							{
								
								JOptionPane.showMessageDialog(null,"בהגדרת מקום למנה יש להקיש ספרות בלבד");
								
								 return;	
								
							}
							try{
								
								float f=Float.parseFloat(weightTxt.getText());
								
							}catch(NumberFormatException e1)
							{
								
								JOptionPane.showMessageDialog(null,"בהגדרת כמות המנה יש להקיש ספרות בלבד");
								
							}
					    		 if(flagTypeChooseOfRecipe=="בחר סוג")
										JOptionPane.showMessageDialog(null,"יש לקבוע סוג המנה");	
					    		 
							else{
							
							totalCost=totalCost+Float.parseFloat(reallyCostItemTxt.getText());
							costTxt.setText(Float.toString(totalCost));
							allRecipeModel.removeElement(selectedItem);
						    menuRecipesModel.addElement(selectedItem);
						   
						for(int i=0; i<res_allRecipes.size();i++)
						{
						     if(res_allRecipes.get(i).getName().equals(selectedItem))
						     {
						    	 BusinessMenuRightList rightList = new BusinessMenuRightList();  	
						    	 					    	 
						    	 rightList.setName(res_allRecipes.get(i).getName());
						    	 rightList.setRole(roleTxt.getText());
						    	 rightList.setCost(Float.parseFloat(costItemTxt.getText()));
						    	 rightList.setReallyCost(Float.parseFloat(reallyCostItemTxt.getText()));
						    	 rightList.setQuantity(Integer.parseInt(weightTxt.getText()));
						    	 rightList.setIsSelectable(flagTypeChooseOfRecipe);
						    	 rightList.setRid((res_allRecipes.get(i).getRid()));
						    	 
						    	 if(res_menuRecipes.size()==0)
						    	 {
						    		 res_menuRecipes.add(rightList);
						    		 
						    	 }
						    	 else
						    	 {
						    		 addRecipeToMenu(rightList.getRole(),rightList);
						    	 }
						    	 
						    	 NotEdditibleTable orderModel = (NotEdditibleTable) (tbl
											.getModel());
						    	 
						    		orderModel.setDataVector(parseVectorObjectToVectorVector(res_menuRecipes), tblheader);
						    	//	tbl.setModel(addRicipeToMenu(orderModel,tblheader,rightList));
						    		tbl.setModel(orderModel);
						    		for(int x=0;x<5;x++){
										tbl.getColumnModel().getColumn(x).setCellRenderer( centerRenderer );
								        }
						    	    res_allRecipesTemp.add(res_allRecipes.get(i));
						    	    res_allRecipes.remove(i);
						    	
						    	 
						    	 recipeTxt.setText("");
						    	 roleTxt.setText("");
						    	 weightTxt.setText("");
						    	 costItemTxt.setText("");
						    	 reallyCostItemTxt.setText("");
						    	 flagTypeChooseOfRecipe="בחר סוג";
						    	 typeChooseCB.setSelectedItem("בחר סוג");
						    	 roleTxt.setEditable(false);
								 recipeTxt.setEditable(false);
								// weightTxt.setEditable(false);
								 reallyCostItemTxt.setEditable(false);
						    	 break;
						     }//if
						    	
						     }//for
															    		 
						     }
						     
						}
					} //if (selectedItem!=null)
					
					else
					{
						JOptionPane.showMessageDialog(null,"יש לבחור פריט");
					}
							
				}
			});
				
			return rightButton;		
		}
		
		private void addRecipeToMenu(String role,BusinessMenuRightList rList)
		{
			int i;
			BusinessMenuRightList tempList = new BusinessMenuRightList();
			Vector<BusinessMenuRightList> tempVector = new Vector<BusinessMenuRightList>();
						
			for(i=0;i<res_menuRecipes.size();i++)
			{
				if(Integer.parseInt(res_menuRecipes.get(i).getRole())<Integer.parseInt(role))
				 		
					tempVector.add(res_menuRecipes.get(i));
							
				else
				{
					if(res_menuRecipes.get(i).getRole().equals(role))
					{
						tempVector.add(rList);
						for(int j=i;j<res_menuRecipes.size();j++)
						{
							tempList=res_menuRecipes.get(j);
					        tempList.setRole(Integer.toString(Integer.parseInt(tempList.getRole())+1));
					    	tempVector.add(tempList);
						}
						break;
					}
					else
					{
							tempVector.add(rList);
						for(int k=i;k<res_menuRecipes.size();k++)
						{
							tempVector.add(res_menuRecipes.get(k));	
							
						}
						break;
					}
				}
					
			}
			if(i==res_menuRecipes.size())
				tempVector.add(rList);
			res_menuRecipes.removeAllElements();
			
			for(i=0;i<tempVector.size();i++)
			{
				res_menuRecipes.addElement(tempVector.get(i));
				
			}
		}
		
		
		private Vector<Vector> parseVectorObjectToVectorVector (Vector<BusinessMenuRightList> vectorObj)
		{
			
			Vector<Vector> vectorvector=new Vector<Vector>();
			for(int i=0;i<vectorObj.size();i++)
			{
				
				Vector<String> vector=new Vector<String>();
				vector.add(vectorObj.get(i).getName());
				vector.add(vectorObj.get(i).getRole());
				vector.add(Float.toString(vectorObj.get(i).getCost()));
			    vector.add(Float.toString(vectorObj.get(i).getReallyCost()));
				vector.add(Integer.toString(vectorObj.get(i).getQuantity()));
				vectorvector.add(vector);
			}
			
			return vectorvector;
			
			
			
		}
		
		/**
		 * Method for creation JButton 	leftButton that transfer selected recipe from JList with selected recipes  of new menu 
		 * to JList with all recipes that restaurant has
		 * 
		 * @return leftButton
		 */
		private JButton getLeftButton()
		{
        leftButton=new JButton("<---");
			
			leftButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					String selectedItem=(String)menuRecipesList.getSelectedValue();
					if (selectedItem!=null)
					{
						menuRecipesModel.removeElement(selectedItem);
						allRecipeModel.addElement(selectedItem);
						for(int i=0; i<res_menuRecipes.size();i++)
						{
							 
						     if(res_menuRecipes.get(i).getName().equals(selectedItem))
						     {
						    	 
						    	
						    	 for(int j=0;j<res_allRecipesTemp.size();j++)
						    	 {
						    		
						    		 if(res_allRecipesTemp.get(j).getName().equals(res_menuRecipes.get(i).getName()))
						    		 {
						    			 
						    			 res_allRecipes.add(res_allRecipesTemp.get(j));
						    			 res_allRecipesTemp.remove(j);
						    			 break;     
						    		 }
						    		             
						    	 }
						    	 res_menuRecipes= removeRecipe(i);      
						    	 totalCost=totalCost-(Float.parseFloat(reallyCostItemTxt.getText()));
						    	 costTxt.setText(String.valueOf(totalCost));
						    	 recipeTxt.setText("");
						    	 roleTxt.setText("");
						    	 reallyCostItemTxt.setText("");
						    	 weightTxt.setText("");
						    	 typeChooseCB.setSelectedIndex(0);
						    	 
						    	 
						    	 NotEdditibleTable orderModel = (NotEdditibleTable) (tbl
											.getModel());
						    		orderModel.setDataVector(parseVectorObjectToVectorVector(res_menuRecipes), tblheader);
						    		tbl.setModel(orderModel);
						    		for(int x=0;x<5;x++){
										tbl.getColumnModel().getColumn(x).setCellRenderer( centerRenderer );
								        }
						    	 
						    	 break;
						     }
						}
						//tbl.repaint();
						
					} 
					
					else
					{
						JOptionPane.showMessageDialog(null,"יש לבחור פריט");
					}
							
				}
			});
			
			return leftButton;		
		}
			
		private Vector<BusinessMenuRightList> removeRecipe(int index)
		{
			BusinessMenuRightList tempList = new BusinessMenuRightList();
			Vector<BusinessMenuRightList> tempVector = new Vector<BusinessMenuRightList>();
			String role=res_menuRecipes.get(index).getRole();
			for(int i=0;i<res_menuRecipes.size();i++)
			{
				
				if(Integer.parseInt(res_menuRecipes.get(i).getRole())<Integer.parseInt(role))
					tempVector.add(res_menuRecipes.get(i));
				else
				{
					if((res_menuRecipes.get(i).getRole())==role)
					{
				
					}
					else
					{
					res_menuRecipes.get(i).setRole(Integer.toString((Integer.parseInt(res_menuRecipes.get(i).getRole())-1)));
					tempVector.add(res_menuRecipes.get(i));
					
					}
				}
			}
			return tempVector;
		}	
		
		//=====================panels for rightPanel ============================================	
		/**Method for creation JPanel rightPanel that consists of  3 panels (DetailsPanel,TablePanel,ButtonsPanel)
		 * return rightPanel
		 */		
		private JPanel getRightPanel()
		{
			rightPanel=new JPanel();
			rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
			JScrollPane scrollPane = new JScrollPane(getTablePanel());
			rightPanel.add(getDetailsPanel());            // panel with buttons for getting details for new menu
			rightPanel.add(getTablePanel());             // panel with recipes table
			rightPanel.add(getButtonsPanel());           // panel with save and cancel buttons 
			
		return rightPanel;
		}
		
		/**
		 * Method for creation JPanel tablePanel that includes JTable tbl with recipes of this  menu(all recipe that we see them in 
		 * menuRecipeListPanel )
		 * @return tablePanel
		 */
		private JPanel getTablePanel()
		{
			
			
			tablePanel=new JPanel();
			tablePanel.setBorder(new TitledBorder(null, "המתכונים המשתתפים בתפריט", TitledBorder.CENTER, TitledBorder.TOP, null, null));
			tblheader=new Vector<String>();
			tblheader.add("מנה");
			tblheader.add("מקום ");
			tblheader.add("עלות כללית");
			tblheader.add("עלות נבחרת");
			tblheader.add("כמות");
			
			dtm=new NotEdditibleTable(parseVectorObjectToVectorVector(res_menuRecipes),tblheader);	 	 
			tbl = new JTable(dtm);
			
			centerRenderer = new DefaultTableCellRenderer();
			centerRenderer.setHorizontalAlignment( JLabel.CENTER );
			for(int x=0;x<5;x++){
				tbl.getColumnModel().getColumn(x).setCellRenderer( centerRenderer );
		        }
			
			tbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
			tbl.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
			tbl.setFont(new Font("David", Font.BOLD, 16));
			tbl.getTableHeader().setFont( new Font( "Arial" , Font.BOLD, 17 ));
			tbl.getTableHeader().setBackground(new Color(173,216,230));
			tbl.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); 
			
		    tbl.setRowHeight(30);
			tbl.setFillsViewportHeight(true);
	        tbl.setGridColor(new Color(25, 25, 112));
	        tbl.setBackground(new Color(255, 240, 245));
	        tbl.setForeground(new Color(0, 0, 0));
	        tbl.setAutoCreateRowSorter(true);
	        
	        JScrollPane scrollPane = new JScrollPane(tbl);
	        scrollPane.setPreferredSize(new Dimension(300,180));
	        tablePanel.add(scrollPane);
			
		return tablePanel;
		}
		
		/**
		 * Method for creation JPanel buttonsPanel that includes buttons for control of the new menu(Save and Cancel)
		 * @return
		 */
		private JPanel getButtonsPanel()
		{
			buttonsPanel=new JPanel();
			buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
			buttonsPanel.add(getSaveButton());
			buttonsPanel.add(Box.createHorizontalStrut(25));
			buttonsPanel.add(getCancelButton());
			
		return buttonsPanel;
			
		}
		
		/**
		 * Method for creation JButton saveButton  for saving of the new menu in database
		 * @return saveButton
		 */
		private JButton getSaveButton()
		{
			JButton saveButton=new JButton("שמור");
			saveButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int result1;
					result1=inputCheck();		
					if(result1==0)
					{
						
								Vector<String>	menuDetails = new Vector<String>();
								menuDetails.add(textField_MenuId.getText());								
								menuDetails.add(textField_nameMenu.getText());								
								menuDetails.add(textField_price.getText());								
								menuDetails.add(flagStatusOfMenu);
								menuDetails.add(business_menu);
								
								MessageUpdateBusinessMenu msgUpdateBusinessMenu= new MessageUpdateBusinessMenu(res_menuRecipes,menuDetails);
						try {
							mainMenu.ms.client.sendToServer(msgUpdateBusinessMenu);
							MessageSavingReply result = (MessageSavingReply)mainMenu.ms.client.GetMessage();
						if (result.getResult()== '0')
					    	{
					    		JOptionPane.showMessageDialog(null,"בעיית תקשורת 03");
					    	}
					    else 
					    	{
					    		JOptionPane.showMessageDialog(null,"הנתונים נשמרו בהצלחה");
					    	}
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					
				}
			});
		return saveButton;
		}
		
		/**
		 * Method for creation JButton cancelButton  for an exit from this window without saving of new menu
		 * @return
		 */
		private JButton getCancelButton()
		{   final Vector<String> arr = new Vector<String>();
			JButton cancelButton=new JButton("ביטול");
			cancelButton.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					MessageShowBusinessMenus msgShowMenu=new MessageShowBusinessMenus( );
					
					try {
						mainMenu.ms.client.sendToServer(msgShowMenu);
						MessageShowBusinessMenusReply resultMenu=(MessageShowBusinessMenusReply)mainMenu.ms.client.GetMessage();
						mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
						mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
						mainMenu.getContentPane().add(new PfSearch_business_menu(mainMenu,resultMenu.getResultMenu()), BorderLayout.CENTER);	
						mainMenu.getContentPane().add(new PanelFunctionMenuListAllBusMenu(mainMenu,arr), BorderLayout.EAST);
						mainMenu.getContentPane().validate();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
												
				}
			});
			
		return cancelButton;
		}
		
		/**
		 * Method for creation JPanel detailsPanel that includes JTextFields for filling(changing) of data of this menu(ID,name,price)and JComboBox 
		 * for  a status choice
		 * @return
		 */
		private JPanel getDetailsPanel()
		{
			
			detailsPanel=new JPanel();
			detailsPanel.setBorder(new TitledBorder(null, "פרטים של תפריט החדש", TitledBorder.CENTER, TitledBorder.TOP, null, null));
			detailsPanel.setLayout(new SpringLayout());
			textField_MenuId = new JTextField();
			textField_MenuId.setHorizontalAlignment(JTextField.RIGHT);
			textField_MenuId.setFont(new Font("Tahoma", Font.PLAIN, 16));
			
			
			textField_MenuId.setText(menuDetails.get(0));
			textField_MenuId.setColumns(10);
			textField_MenuId.setEditable(false);
			textField_MenuId.setBackground(Color.pink);
			
			JLabel mid = new JLabel("מספר תפריט:", JLabel.TRAILING);
			mid.setForeground(new Color(75, 0, 130));
			mid.setFont(new Font("Tahoma", Font.BOLD, 12));
			mid.setLabelFor(textField_MenuId);
			
			detailsPanel.add(textField_MenuId);
			detailsPanel.add(mid);
			
			textField_nameMenu = new JTextField();
			textField_nameMenu.setHorizontalAlignment(JTextField.RIGHT);
			textField_nameMenu.setText(menuDetails.get(1));
			textField_nameMenu.setFont(new Font("Tahoma", Font.PLAIN, 13));
			textField_nameMenu.setColumns(10);	
			
			
			JLabel name = new JLabel("שם תפריט:", JLabel.TRAILING);
			name.setForeground(new Color(75, 0, 130));
			name.setFont(new Font("Tahoma", Font.BOLD, 12));
			name.setLabelFor(textField_nameMenu);	
			
			//======================================================CHECK FOR CORRECT INPUT NAME==================================================
			/**
			 * CHECK FOR CORRECT INPUT NAME
			 */
			KeyListener keyListener1 = new KeyListener() 
			{		      
				public void keyPressed(KeyEvent arg0) {}

				public void keyReleased(KeyEvent arg0) 
				{
					JTextField nameField1 = (JTextField)arg0.getSource();
					String selectedName1 = (String)nameField1.getText();
					if(selectedName1.length()==0)
					{
						textField_nameMenu.setBackground(Color.white);
					}
					for(int i=0;i<selectedName1.length();i++)
					{
					
						textField_nameMenu.setBackground(Color.pink);
					
					}
				}

				public void keyTyped(KeyEvent arg0) {}		
			};	
			textField_nameMenu.addKeyListener(keyListener1);		
			
			//======================================================================================================================
			
			detailsPanel.add(textField_nameMenu);
			detailsPanel.add(name);
			
			textField_price = new JTextField();
			textField_price.setText(menuDetails.get(2));
			textField_price.setFont(new Font("Tahoma", Font.PLAIN, 13));
			textField_price.setColumns(10);
			
			JLabel labelPrice = new JLabel("מחיר לתפריט:", JLabel.TRAILING);
			labelPrice.setForeground(new Color(75, 0, 130));
			labelPrice.setFont(new Font("Tahoma", Font.BOLD, 12));
			labelPrice.setLabelFor(textField_price);
			
		//===========================================CHECK FOR CORRECT INPUT PRICE==================================================
			/**
			 * CHECK FOR CORRECT INPUT PRICE
			 */
			
			KeyListener keyListener = new KeyListener() 
			{		      
				public void keyPressed(KeyEvent arg0) {}

				public void keyReleased(KeyEvent arg0) 
				{
					JTextField nameField = (JTextField)arg0.getSource();
					String selectedName = (String)nameField.getText();
					if(selectedName.length()==0)
					{
						textField_price.setBackground(Color.white);
					}
					for(int i=0;i<selectedName.length();i++)
					{
					if (selectedName.charAt(i) <'0'|| selectedName.charAt(i)>'9')
		    		 {
		    			 
						textField_price.setBackground(Color.RED);
						 break;
		    		 }
					else
					{
						textField_price.setBackground(Color.pink);
					}
					}
				}

				public void keyTyped(KeyEvent arg0) {}		
			};
			
			textField_price.addKeyListener(keyListener);	
		//=============================================================================================================================
			detailsPanel.add(textField_price);
			detailsPanel.add(labelPrice);
		   	
			//===========================================CHECK FOR CORRECT INPUT status==================================================
			/**
		   	 * CHECK FOR CORRECT INPUT status
		   	 */
			statusMenu=new JComboBox(new ConstantObjects().getMenuStatus());
			statusMenu.setSelectedItem(menuDetails.get(3));
			statusMenu.addActionListener(new java.awt.event.ActionListener() 
			  	{
					public void actionPerformed(java.awt.event.ActionEvent e) {
						JComboBox roleBox = (JComboBox)e.getSource();
					    String selectedRole = (String)roleBox.getSelectedItem(); 
					    if(selectedRole.equals("פעיל") || selectedRole.equals("לא פעיל"))
					    {
					    	if(selectedRole.equals("פעיל"))
					    		flagStatusOfMenu="פעיל";
					    	else
					    		flagStatusOfMenu="לא פעיל";
					    					  
					    	statusMenu.setBackground(Color.pink);
					  
				    	}
					    else
					    {
					    	
					    	statusMenu.setBackground(Color.RED);
					    }
					
						} 
				});	
			
			//============================================================================================================================
			
				JLabel label_1 = new JLabel("סטטוס:", JLabel.TRAILING);
				label_1.setForeground(new Color(75, 0, 130));
				label_1.setFont(new Font("Tahoma", Font.BOLD, 12));
				label_1.setLabelFor(statusMenu);
				detailsPanel.add(statusMenu);
				detailsPanel.add(label_1);	
			
			
			SpringUtilities.makeCompactGrid(detailsPanel, 4, 2, //rows, cols
				     100, 50, //initX, initY
				        10, 50); //xPad, yPad
			
		return detailsPanel;
		}
		
		
		/**
		 * Method for check correctness of input
		 * @return Integer result
		 */		
		private int inputCheck()
		 {
			int result=0;
			
			
			//=================================================check for empty price and name================================		
			/**
			 * 	check for empty price and name	
			 */			
			String price=textField_price.getText();
			String name=textField_nameMenu.getText();
			String selectedRole = (String)statusMenu.getSelectedItem(); ; 
			if(price.isEmpty() && name.isEmpty())
			{
				JOptionPane.showMessageDialog(null,"יש להקיש שם ומחיר לתפריט");	
				textField_nameMenu.setBackground(Color.RED);
				textField_price.setBackground(Color.RED);
				result=1;
			}
			else
				if(price.isEmpty())
				{
					JOptionPane.showMessageDialog(null,"יש לתת מחיר");	
					textField_price.setBackground(Color.RED);
					result=1;
				}
				else
				if(name.isEmpty())
				{
					JOptionPane.showMessageDialog(null,"יש לתת שם לתפריט");	
					textField_nameMenu.setBackground(Color.RED);
					result=1;
				}
			
			//=================================================check for price================================	
			/**
			 * check correctness of price
			 */			
			if(result==0)
			{
			for(int i=0;i<price.length();i++)
			{
			if (price.charAt(i) <'0'|| price.charAt(i)>'9')
			 {
				JOptionPane.showMessageDialog(null,"חיר שגוי.יש להקיש ספרות לבד.");	
				textField_price.setBackground(Color.RED);
				result=1;
				 break;
			 }
			else
			{
				textField_price.setBackground(Color.pink);
			}
			
			}
			
			
		 }
			
			//=================================================check for status================================		
			/**
			 * Check correctness of status
			 */
			if(result==0)
			{
			if(selectedRole.equals("פעיל") || selectedRole.equals("לא פעיל"))
		    {
		    	
		    	statusMenu.setBackground(Color.pink);
		    		    	
	    	}
		    else
		    {
		    	JOptionPane.showMessageDialog(null,"יש לבחור סטטוס");	
		    	statusMenu.setBackground(Color.RED);
		    	result=1;
		    }
			
			}
			return result;
	}
		
		NotEdditibleTable addRicipeToMenu(NotEdditibleTable model,Vector<String> tableH, Vector<String> recipe)
		{
			int i;
			String str_role=recipe.get(1);
			Vector<Vector<String>> newMenu=new Vector<Vector<String>>();
			int role=Integer.parseInt(str_role);
			Vector<Vector<String>> menu =model.getDataVector();
			System.out.println("menu.size()"+menu.size());
			for( i=0; i<menu.size();i++)
			{
				int currRole=Integer.parseInt(menu.get(i).get(1));
				Vector<String> curRecipe=menu.get(i);
				if(currRole<role )
				{
					newMenu.add(curRecipe);
					
					
				}
				else
				{
					//currRole++;
					if(currRole==role)
					{	
					 					
					 newMenu.add(recipe);
					 for(int k=i;k<menu.size();k++)
						{
							Vector<String> curRecipe2=menu.get(k);
							curRecipe2.set(1, Integer.toString(Integer.parseInt(curRecipe2.get(1))+1));
							newMenu.add(curRecipe2);
						}
					 break;
					}
					else{
				
					 newMenu.add(recipe);
					
					for(int j=i;j<menu.size();j++)
					{
						Vector<String> curRecipe1=menu.get(j);
						newMenu.add(curRecipe1);
					}
					
					
					break;
				}}
				
			}
			if(i==menu.size())
			newMenu.add(recipe);
			model.setDataVector(newMenu, tableH);
			return model;
			
		}
		
		
		Vector<Vector> removeRecipe (Vector<Vector> res_menuRecipes2 , int indexRecipe){
			
			Vector<Vector> newMenu=new Vector<Vector>();
			int role=Integer.parseInt((String) res_menuRecipes2.get(indexRecipe).get(1));
			res_menuRecipes2.remove(indexRecipe);
			if(res_menuRecipes2.size()==1)
			{
				Vector<String> curRecipe=res_menuRecipes2.get(0);
				curRecipe.set(1,Integer.toString(1));
				newMenu.add(curRecipe);
				
			}
			else
			{
			for(int i=0; i<res_menuRecipes2.size();i++)
				
			{
				int curRole=Integer.parseInt((String) res_menuRecipes2.get(i).get(1));
				Vector<String> curRecipe=res_menuRecipes2.get(i);
				if (curRole<role)
				{
					//curRecipe.set(1,Integer.toBinaryString(curRole))
					newMenu.add(curRecipe);
					
				}
				else
				{
					curRole--;
					curRecipe.set(1,Integer.toString(curRole));
					newMenu.add(curRecipe);
				}
				
			}
			}
			return newMenu;
		}
}
